/***************************************************************************
 创建者：          hualei
 开始时间：      2018.12.20
 copyright:(C)    深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   ROLLER 滚筒指令属性编辑类
 *
 ***************************************************************************/
#include "../../programView/programview.h"
#include "rollerinstructionview.h"
#include "ui_rollerinstructionview.h"

RollerInstructionView::RollerInstructionView(int styleId,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::RollerInstructionView)
{
    ui->setupUi(this);
    initialDisplayStyle(styleId);
}

void RollerInstructionView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->forward_Btn->setGeometry(10,350,70,40);
        ui->save_Btn->setGeometry(360,350,70,40);
        break;
    default:
        break;
    }
}

void RollerInstructionView::getInput()
{

//    rollerType = E_ROLLER_GENERAL;
    timeOutValue = ui->TimeOut_Value_Edit->text().toInt();
    jmpLbValue = ui->JMP_LB_Edit->text().toInt();
    noteStr = ui->Note_Edit->text();
}

void RollerInstructionView::updateView()
{
    ui->Positive_RadioBtn->setChecked(false);
    ui->Reverse_RadioBtn->setChecked(false);
    ui->Positive_RadioBtn_right->setChecked(false);
    ui->Reverse_RadioBtn_right->setChecked(false);

    if(rollerDirectionType == E_ROLLER_LEFT_LOAD)
    {
        ui->Positive_RadioBtn->setChecked(true);
    }
    else if(rollerDirectionType == E_ROLLER_LEFT_DOWNLOAD)
    {
        ui->Reverse_RadioBtn->setChecked(true);
    }
    else if(rollerDirectionType == E_ROLLER_RIGHT_LOAD)
    {
        ui->Positive_RadioBtn_right->setChecked(true);
    }
    else if(rollerDirectionType == E_ROLLER_RIGHT_DOWNLOAD)
    {
        ui->Reverse_RadioBtn_right->setChecked(true);
    }

    ui->TimeOut_Value_Edit->setText(QString::number(timeOutValue));
    ui->JMP_LB_Edit->setText(QString::number(jmpLbValue));
    ui->Note_Edit->setText(noteStr);
}

void RollerInstructionView::changeLanguage(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/rollerInstructionView.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    ui->retranslateUi(this);
}

void RollerInstructionView::on_save_Btn_clicked()
{
    getInput();
    emit finishEditInstructionSignal();
    emit saveInstruction(instructionStr);
}

void RollerInstructionView::on_forward_Btn_clicked()
{
    this->close();
    programView->instructionListFlag = 0;
    programView->editInstructionViewShowOrHide();
}

void RollerInstructionView::on_clearNote_Btn_clicked()
{
    ui->Note_Edit->clear();
    emit cleanNoteSignal();
}

void RollerInstructionView::on_Positive_RadioBtn_clicked()
{
    rollerDirectionType = E_ROLLER_LEFT_LOAD;
}

void RollerInstructionView::on_Reverse_RadioBtn_clicked()
{
    rollerDirectionType = E_ROLLER_LEFT_DOWNLOAD;
}

void RollerInstructionView::on_Positive_RadioBtn_right_clicked()
{
    rollerDirectionType = E_ROLLER_RIGHT_LOAD;
}

void RollerInstructionView::on_Reverse_RadioBtn_right_clicked()
{
    rollerDirectionType = E_ROLLER_RIGHT_DOWNLOAD;
}
